﻿/*
 * @Autor: PK
 * @Date: 2022/01/11 20:34:SS
 */

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using PropertyChanged;
using ShkSimulation.core.factory;
using ShkSimulation.core.template.customer;
using ShkSimulation.desktop.Annotations;
using static ShkSimulation.carsharing.impl.create.DefaultDemandManager;

namespace ShkSimulation.desktop.setting.model {

	[AddINotifyPropertyChangedInterface]
	public class DemandConfigModel: INotifyPropertyChanged {
		
		public DemandConfigModel() {
		}
		
		public DemandConfigModel(CreateParam param) {
			this.Id = Convert.ToInt32(param[DemandId]);
			this.OriginId = Convert.ToInt32(param[DemandOriginId]);
			this.DestinationId = Convert.ToInt32(param[DemandDestinationId]);
			this.DemandValue = Convert.ToDouble(param[DemandValueKey]);
			this.Unit = Convert.ToString(param[DemandUnit]);
			this.DemandTimespanValue = DemandManager.DemandToTimeSpanWithTimeUnit(DemandValue, Unit);
			this.InitWhenStart = Convert.ToBoolean(param[DemandInitWhenStart]);
			this.RoadIds = Convert.ToString(param[DemandRoadIds]);
		}

		public DemandConfigModel(int id, int origin, int destinationId) {
			this.Id = id;
			this.OriginId = origin;
			this.DestinationId = destinationId;
			this.Unit = "H";
		}

		public int Id { get; set; }
		public int OriginId { get; set; }
		public int DestinationId { get; set; }
		public double DemandValue { get; set; }
		public string Unit { get; set; }
		public TimeSpan DemandTimespanValue { get; set; }
		public bool InitWhenStart { get; set; }
		public string RoadIds { get; set; }

		public event PropertyChangedEventHandler PropertyChanged;

		[NotifyPropertyChangedInvocator]
		protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {
			PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}

		public override string ToString() {
			return $"Id: {Id}, OriginId: {OriginId}, DestinationId: {DestinationId}, DemandValue: {DemandValue}, Unit: {Unit}, DemandTimespanValue: {DemandTimespanValue}, InitWhenStart: {InitWhenStart}, RoadIds: {RoadIds}";
		}

	}

}